Ubuntu 16.04
Sponsored Link

Set Disk Quota
2016/09/08
 
Limit amount of disk usage to set Disk Quota.
For example on here, Set Quota on /home which is ext4 formatted.
[1] Install Quota tools.
root@dlp:~#
apt-get -y install quota quotatool
[2] Enable Quota to add mount options.
root@dlp:~#
umount /home

root@dlp:~#
mount -o usrquota,grpquota /dev/sdb1 /home
root@dlp:~#
vi /etc/fstab
# add options

/dev/mapper/VolGroup-lv_root /          ext4    defaults        1 1
UUID=cf3f9660-e40d-459d-8763 /boot      ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap       swap    defaults        0 0
tmpfs                        /dev/shm   tmpfs   defaults        0 0
devpts                       /dev/pts   devpts  gid=5,mode=620  0 0
sysfs                        /sys       sysfs   defaults        0 0
proc                         /proc      proc    defaults        0 0
/dev/sdb1                    /home      xfs     defaults,usrquota,grpquota 0 0
[3] Set user Quota. For example, Apply quota to "ubuntu" user.
# create quota config

root@dlp:~#
quotacheck -um /home
# enable quota

root@dlp:~#
quotaon -uv /home

/dev/sdb1 [/home]: user quotas turned on
# show status

root@dlp:~#
quotaon -ap

group quota on /home (/dev/sdb1) is off
user quota on /home (/dev/sdb1) is on
# set quota to "ubuntu"

root@dlp:~#
edquota -u ubuntu
# set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)

Disk quotas for user ubuntu (uid 500):
  Filesystem   blocks     soft       hard   inodes   soft   hard
  /dev/sdb1    16      4096000    5120000        7      0      0

# show status

root@dlp:~#
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0
ubuntu    --      16 4096000 5120000              4     0     0
[4] If you'd like to apply setting of quota of a user to another user, set like follows.
# apply setting of "ubuntu" to "fedora"

root@dlp:~#
edquota -p ubuntu fedora

root@dlp:~#
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0
ubuntu    +- 5120000 4096000 5120000  6days       7     0     0
fedora    --       4 4096000 5120000              4     0     0
[5] Set group Quota. For example, Apply quota to "ubuntu" group.
# create quota config

root@dlp:~#
quotacheck -gm /home
# enable quota

root@dlp:~#
quotaon -gv /home

/dev/sdb1 [/home]: group quotas turned on
# show status

root@dlp:~#
quotaon -ap

group quota on /home (/dev/sdb1) is on
user quota on /home (/dev/sdb1) is on
# set quota to "ubuntu"

root@dlp:~#
edquota -g ubuntu
# set Soft Limit 4G, Hard Limit 5G (specify with kilo bytes)

Disk quotas for group ubuntu (gid 500):
  Filesystem       blocks       soft       hard     inodes   soft   hard
  /dev/sdb1       5120000    4096000    5120000          7      0      0

# show status

root@dlp:~#
*** Report for group quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Group           used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0
ubuntu    +- 5120000 4096000 5120000  6days       7     0     0
fedora    --      16       0       0              4     0     0
[6] It's possible to send warnings to use Warnquota.
This setting needs SMTP server on your server.
root@dlp:~#
vi /etc/quotatab
# add device and description which quota is set

/dev/sdb1: Your Home Director
root@dlp:~#
vi /etc/warnquota.conf
# change mail sender or others if you need

MAIL_CMD        = "/usr/sbin/sendmail -t"
FROM            = "root@localhost"
# but they don't have to be:
SUBJECT         = Over quota
CC_TO           = "root@localhost"
SUPPORT         = "root@localhost"
PHONE           = "<enter your phone number here>"
#
CHARSET         = UTF-8

# run warnquota

root@dlp:~#
warnquota -s
# if a user is over the limit when warnquota runs, following warning is sent

From root@dlp.srv.world  Fri Oct 23 09:38:10 2011
Return-Path: <root@dlp.srv.world>
X-Original-To: ubuntu
Delivered-To: ubuntu@dlp.srv.world
From: root@srv.world
Reply-To: root@srv.world
Subject: NOTE: You are exceeding your allocated disk space limits
To: ubuntu@dlp.srv.world
Cc: root@srv.world
Date: Fri, 23 Oct 2011 09:38:10 +0900 (JST)
Status: R

Your disk usage has exceeded the agreed limits on this server
Please delete any unnecessary files on following filesystems:

Your Home Director (/dev/sdb1)

                        Block limits               File limits
Filesystem           used    soft    hard  grace    used  soft  hard  grace
/dev/sdb1      +-   5000M   4000M   5000M  6days       7     0     0

root@srv.world
 
Tweet